//
// Created by sjjmw on 3/24/2022.
//
#include "iostream"
#include "vector"
#include "list"
#include "algorithm"
#include "string"
#include "unordered_map"
#include "cmath"
#include<iomanip>
#include "string"
#include "map"
#include "list"

//输入写错，输入是顺时针
struct State{
    int moban;
    int depth;
    char op;
    State*last;
};
struct Sol{
    std::vector<int> tag;
    std::vector<int> buf;
    int tar=0;
    std::list<State> queue;
    std::list<State> out_queue;
    int num_of_buf(){
        int sum=0;
        for(int i=0;i<buf.size();i++){
            sum*=10;
            sum+=buf[i];
        }
        return sum;
    }
    void num_2_buf(int n){
        for(int i=buf.size()-1;i>=0;i--){
            buf[i]=n%10;
            n/=10;
        }
    }
    int opA(int n){
        num_2_buf(n);
        for(int i=0;i<4;i++){
            std::swap(buf[i],buf[i+4]);
        }
        return num_of_buf();
    }
    int opB(int n){
        num_2_buf(n);
        int b_3=buf[3];
        int b_7=buf[7];
        for(int i=3;i>0;i--){
            buf[i]=buf[i-1];
        }
        for(int i=7;i>4;i--){
            buf[i]=buf[i-1];
        }
        buf[0]=b_3;
        buf[4]=b_7;
        return num_of_buf();
    }
    int opC(int n){
        num_2_buf(n);
        auto buf_5=buf[5];

        buf[5]=buf[6];
        buf[6]=buf[2];
        buf[2]=buf[1];
        buf[1]=buf_5;
//        buf[0]=buf_4;
        return num_of_buf();
    }
    void handle(
            ){
        buf.resize(8);
        tag.resize(87654322);
        for(int i=0;i<4;i++){
            std::cin>>buf[i];
        }
        for(int i=7;i>=4;i--){
            std::cin>>buf[i];
        }
        tar=num_of_buf();
//        for(int i=0;i<8;i++){
//            tar*=10;
//            int in;std::cin>>in;
//            tar+=in;
//        }
        queue.push_back({12348765,0});
        int ans=0;
        State* final= nullptr;
        while (!queue.empty()){
            out_queue.splice(out_queue.begin(),queue,queue.begin());
            auto &front=out_queue.front();
            if(front.moban==tar){
                ans=front.depth;
                final=&front;
//                return;
                break;
            }
            int op=opA(front.moban);
            if(!tag[op]){
                tag[op]=1;
                queue.push_back({op,
                                 front.depth+1,'A',&front});
            }
            op=opB(front.moban);
            if(!tag[op]){
                tag[op]=1;
                queue.push_back({op,
                                 front.depth+1,'B',&front});
            }
            op=opC(front.moban);
            if(!tag[op]){
                tag[op]=1;
                queue.push_back({op,
                                 front.depth+1,'C',&front});
            }

//            queue.pop_front();
        }
        std::vector<char> stack;
        stack.reserve(ans);
        while (final){
            stack.push_back(final->op);
//            printf("%d\n%d\n\n",final->moban/10000,final->moban%10000);
            final=final->last;
        }
        printf("%d\n",ans);
        for(int i=stack.size()-2;i>=0;i--){
            printf("%c",stack[i]);
        }
        printf("\n");
    }
};
int main(){
//    int a,b,c;
    float a,b,c,d;
    int e;
//    while(std::cin>>a>>b>>c){
        Sol().handle();
//    }

    return 0;
}